{% extends "member/layout.html" %}

{% block title %}待我审批的项目{% endblock %}

{% block content %}
<div class="row">
    <div class="col-12">
        <!-- 页面标题和统计 -->
        <div class="d-flex justify-content-between align-items-center mb-4">
            <div>
                <h3 class="fw-bold text-primary mb-1">
                    <i class="fas fa-check-double me-2"></i>待我审批的项目
                </h3>
                <p class="text-muted mb-0">您有 <span class="fw-bold text-primary">{{ approvals|length }}</span> 个待审批项目</p>
            </div>
            <div class="d-flex align-items-center">
                <div class="me-3">
                    <span class="badge bg-primary bg-opacity-10 text-primary border border-primary border-opacity-25 rounded-pill px-3 py-2">
                        <i class="fas fa-clock me-1"></i>待处理: {{ approvals|length }}
                    </span>
                </div>
            </div>
        </div>

        <!-- 审批列表 -->
        {% if approvals %}
        <div class="row">
            {% for approval in approvals %}
            <div class="col-lg-6 col-xl-4 mb-4">
                <div class="card dashboard-card border-0 h-100 approval-card">
                    <div class="card-body">
                        <!-- 审批头部 -->
                        <div class="d-flex justify-content-between align-items-start mb-3">
                            <div>
                                <span class="badge bg-{{ 'primary' if approval.type == 'project' else 'success' if approval.is_closure_review else 'info' }} bg-opacity-10 text-{{ 'primary' if approval.type == 'project' else 'success' if approval.is_closure_review else 'info' }} border border-{{ 'primary' if approval.type == 'project' else 'success' if approval.is_closure_review else 'info' }} border-opacity-25 rounded-pill px-3 py-1">
                                    <i class="fas {{ 'fa-project-diagram' if approval.type == 'project' else 'fa-flag-checkered' if approval.is_closure_review else 'fa-tasks' }} me-1"></i>
                                    {{ '结项审批' if approval.is_closure_review else '项目审批' if approval.type == 'project' else '常规审批' }}
                                </span>
                            </div>
                            <div class="dropdown">
                                <button class="btn btn-sm btn-light rounded-circle" type="button" data-bs-toggle="dropdown">
                                    <i class="fas fa-ellipsis-v"></i>
                                </button>
                                <ul class="dropdown-menu dropdown-menu-end">
                                    <li><a class="dropdown-item" href="{{ url_for('member.approval.review_detail', approval_id=approval.id) }}">
                                        <i class="fas fa-info-circle me-2"></i>查看详情
                                    </a></li>
                                    <li><hr class="dropdown-divider"></li>
                                    <li><a class="dropdown-item text-danger" href="#">
                                        <i class="fas fa-flag me-2"></i>标记为紧急
                                    </a></li>
                                </ul>
                            </div>
                        </div>

                        <!-- 项目信息 -->
                        <div class="mb-3">
                            <h5 class="fw-bold text-dark mb-2">{{ approval.project.name }}</h5>
                            <p class="text-muted small mb-0">{{ approval.project.description[:80] }}{% if approval.project.description|length > 80 %}...{% endif %}</p>
                        </div>

                        <!-- 提交人信息 -->
                        <div class="d-flex align-items-center mb-3">
                            <div class="flex-shrink-0">
                                <div class="avatar-sm bg-primary bg-opacity-10 text-primary rounded-circle d-flex align-items-center justify-content-center">
                                    <i class="fas fa-user"></i>
                                </div>
                            </div>
                            <div class="flex-grow-1 ms-2">
                                <h6 class="mb-0 fw-medium">{{ approval.submitter.name }}</h6>
                                <small class="text-muted">提交人</small>
                            </div>
                        </div>

                        <!-- 时间信息 -->
                        <div class="d-flex justify-content-between align-items-center text-muted small mb-3">
                            <div>
                                <i class="fas fa-calendar me-1"></i>
                                {{ approval.created_at.strftime('%Y-%m-%d') }}
                            </div>
                            <div>
                                <i class="fas fa-clock me-1"></i>
                                {{ approval.created_at.strftime('%H:%M') }}
                            </div>
                        </div>

                        <!-- 操作按钮 -->
                        <div class="d-grid gap-2">
                            <a href="{{ url_for('member.approval.review_detail', approval_id=approval.id) }}"
                               class="btn btn-primary">
                                <i class="fas fa-clipboard-check me-2"></i>审核
                            </a>
                        </div>
                    </div>
                </div>
            </div>
            {% endfor %}
        </div>
        {% else %}
        <!-- 空状态 -->
        <div class="card dashboard-card border-0">
            <div class="card-body text-center py-5">
                <div class="mb-4">
                    <i class="fas fa-check-circle text-muted" style="font-size: 4rem;"></i>
                </div>
                <h4 class="text-muted mb-3">暂无待审批项目</h4>
                <p class="text-muted mb-4">您当前没有需要处理的审批申请，请稍后再查看</p>
                <a href="{{ url_for('member.dashboard') }}" class="btn btn-outline-primary">
                    <i class="fas fa-tachometer-alt me-2"></i>返回仪表盘
                </a>
            </div>
        </div>
        {% endif %}
    </div>
</div>

<style>
.approval-card {
    transition: all 0.3s ease;
    border-left: 4px solid transparent;
}

.approval-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1) !important;
    border-left-color: var(--primary-color);
}

.avatar-sm {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.card-body {
    padding: 1.5rem;
}

.badge.rounded-pill {
    font-weight: 500;
    font-size: 0.8rem;
}

.dropdown-toggle::after {
    display: none;
}

.btn-light.rounded-circle {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}
</style>

<script>
document.addEventListener('DOMContentLoaded', function() {
    // 添加卡片悬停效果
    const approvalCards = document.querySelectorAll('.approval-card');

    approvalCards.forEach(card => {
        card.addEventListener('mouseenter', function() {
            this.style.zIndex = '10';
        });

        card.addEventListener('mouseleave', function() {
            this.style.zIndex = '1';
        });
    });

    // 处理紧急标记
    const urgentButtons = document.querySelectorAll('.dropdown-item.text-danger');

    urgentButtons.forEach(button => {
        button.addEventListener('click', function(e) {
            e.preventDefault();
            const card = this.closest('.approval-card');
            card.style.borderLeftColor = '#dc3545';

            // 显示提示
            const toast = document.createElement('div');
            toast.className = 'toast align-items-center text-white bg-danger border-0 position-fixed bottom-0 end-0 m-3';
            toast.innerHTML = `
                <div class="d-flex">
                    <div class="toast-body">
                        <i class="fas fa-flag me-2"></i>已标记为紧急
                    </div>
                    <button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast"></button>
                </div>
            `;
            document.body.appendChild(toast);

            const bsToast = new bootstrap.Toast(toast);
            bsToast.show();

            // 3秒后移除提示
            setTimeout(() => {
                toast.remove();
            }, 3000);
        });
    });
});
</script>
{% endblock %}